import request from '@/utils/request'

/*
  {
    page,
    pagesize,
    keyword,
    departmentId
  }
*/
export const getEmployeeList = (params) => request.get('/sys/user', {
  params
})

/*
  正常接口都是返回json
  这个接口返回二进制文件流 blob
*/
export const exportEmployeeList = () => request.get('/sys/user/export', {
  // params: {},
  // data: {},
  // url: '',
  // method: '',
  // headers: {},

  // 表示这次接口不一般 返回二进制数据 用于下载文件
  responseType: 'blob'
})

export const downloadTemplate = () => request.get('/sys/user/import/template', {
  // params: {},
  // data: {},
  // url: '',
  // method: '',
  // headers: {},

  // 表示这次接口不一般 返回二进制数据 用于下载文件
  responseType: 'blob'
})

/*
  Blob
  FormData 这个接口需要这种类型的数据 而不是普通的json js对象
*/
export const uploadExcel = (file) => {
  const fm = new FormData() // 创建一个空的FormData数据  const obj = {}
  fm.append('file', file) // obj.file = file
  // fm.append('age', 19)
  // fm.append('name', 18)

  return request({
    url: '/sys/user/import',
    method: 'post',
    // data: {
    //   file: file
    // }
    data: fm
  })
}

export const delEmployee = id => request.delete(`/sys/user/${id}`)

export const addEmployee = form => request.post('/sys/user', form)

export const getEmployeeDetail = id => request.get(`/sys/user/${id}`)

export const editEmployee = form =>
  request.put(`/sys/user/${form.id}`, form)

export const assignRoles = (id, roleIds) => request.put('/sys/user/assignRoles', {
  id,
  roleIds
})
